<?php

namespace app\api\controller;

use app\api\model\Paylog;
use think\Request;

class Expense extends Authorization
{
    public function paylog(Request $request){
        $page = $request->param('page',1);
        $limit = $request->param('limit',15);
        $model = new Paylog();

        $count = $model->where('users_id',$request->user->user_id)->count();
        $log = $model->where('users_id',$request->user->user_id)->order('create_time','desc')->page($page,$limit)->select();
        $data = $this->TransferData($log);
        return $this->success('ok',['data'=>$data,'count'=>$count]);
    }
    private function TransferData($array){
        $data = [];
        foreach ($array as $k=>$v){
            $line = [];
            $line['username'] = $v['UserInfo']['nickname'];
            $line['commodity'] = $v['commodity']['name'];
            $line['price'] = $v['value'];
            $line['status'] = $v['status'];
            $line['create_time'] = $v['create_time'];
            $line['update_time'] = $v['update_time'];
            $line['cdk'] = empty($v['cdk']['content']) ? '找不到记录':$v['cdk']['content'];
            $data[] = $line;
        }
        return $data;
    }
}